package com.yi.suprise.response;

import com.yi.suprise.modle.MainModle;
import com.yi.yilib.Callback;
import com.yi.yilib.mvp.YiModel;

import java.util.ArrayList;

import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by zhaoyi on 2016/12/9.
 */

public class MainResponse implements YiModel<MainResponse>{
    private int status;
    private ArrayList<MainModle> modles;

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public ArrayList<MainModle> getModles() {
        return modles;
    }

    public void setModles(ArrayList<MainModle> modles) {
        this.modles = modles;
    }

    @Override
    public void getData(final Callback<MainResponse> callback) {
        Observable.create(new Observable.OnSubscribe<MainResponse>() {

            @Override
            public void call(Subscriber<? super MainResponse> subscriber) {
                MainResponse response = new MainResponse();
                modles = new ArrayList<MainModle>();

                MainModle mainModle = new MainModle();
                mainModle.setName("zhaoyi");
                mainModle.setType(1);
                modles.add(mainModle);

                MainModle mainModle1 = new MainModle();
                mainModle1.setName("zhaoyi");
                mainModle1.setType(2);
                modles.add(mainModle1);

                MainModle mainModle2 = new MainModle();
                mainModle2.setName("zhaoyi");
                mainModle2.setType(1);
                modles.add(mainModle2);

                response.setStatus(1);
                response.setModles(modles);
                subscriber.onNext(response);
                subscriber.onCompleted();
            }
        }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<MainResponse>() {

            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(MainResponse o) {
                callback.onResult(o);
            }
        });
    }
}
